/*
 * File Name : rmdir.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-22
 * Last Edit : 2010-5-22
 */

//#include "user.h"
#include <iostream>

#include "rmdir.h"
#include "my_string.h"

my_rmdir::my_rmdir( std::string *new_parameters)
:command(new_parameters)
{
}

int my_rmdir::run_command(){
  my_string *string_tool = my_string::get_my_string();
  file_system *my_file_system = file_system::get_file_system();
  std::string *parameters = get_parameters();
  std::queue<std::string> *all_strings = string_tool->split_string( ' ' , *parameters );
  int current_user_ID = get_shell_environment()->get_login_users()->top()->get_ID();
  while( !all_strings->empty() ){
    switch( my_file_system->delete_node( &all_strings->front() , current_user_ID ) ){
      case 0: ;break;
      case 1:std::cout<<"directory not empty : "<<all_strings->front()<<std::endl;break;
      case 2:std::cout<<"no this directory : "<<all_strings->front()<<std::endl;break;
      case 3:std::cout<<"rmdir: failed to remove `"<<all_strings->front()<<"': Permission denied"<<std::endl;break;
      default:std::cout<<"file_system::delete() return a unexpact value !"<<std::endl;break;
    }
    all_strings->pop();
  }
  return 0;
}